﻿using System;
using System.Text.RegularExpressions;
using System.Data.SQLite;
using System.Web;

namespace TidyBlog.Data
{
    public class SQLiteDbProvider : DbProvider
    {
        public SQLiteDbProvider()
        {
            ConnStr = Regex.Replace(ConnStr, @"Data Source=(.*?);", (m) => {
                return "Data Source=" + HttpContext.Current.Server.MapPath(m.Groups[1].Value) + ";";
            });
            Factory = new SQLiteFactory();

            CmdTemplates["READ_TOP_N"] += " LIMIT {4}";
            CmdTemplates["LAST_INSERT_ID"] = "SELECT LAST_INSERT_ROWID()";
        }

        public override PagingHelper<T> CreatePagingHelper<T>()
        {
            return new SQLitePagingHelper<T>();
        }
    }
}